Skip to content

Conversation

krakjoe
Copy link
Member

@krakjoe krakjoe commented Sep 1, 2025

A request was made to expose cURL sockets to userland so they may be used in external event loops.

The original request suggested we use curls export of fdsets, this looked pretty restricted though when I came to implement it, and exporting the set for every select also didn't look very performant.

cURL has provided these API's for a long time, a very long time, and we have never implemented them, I'm not certain of the reasons for that.

This has reintroduced resources in cURL, but there's no other reasonable way to do this ...

To opt-in to socket management you must set a timer and socket function.

I'm not certain about this at all, looking for feedback on this approach.

I'm not certain of the consequences of manipulating these streams outside of select(), what happens if you read or write them is unclear.

php_stream *p_stream;

if (stream == NULL && what != CURL_POLL_REMOVE) {
p_stream = (void*) php_stream_fopen_from_fd(socket, "rw", NULL);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be read only.

@krakjoe krakjoe force-pushed the krakjoe/curl-socket-functions branch from 48ebc7b to 5842e34 Compare September 1, 2025 05:01
Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is reasonable to add support for curl_multi_socket_action but as mentioned in the comment, I don't think it should be using streams at all.

php_stream *p_stream;

if (stream == NULL && what != CURL_POLL_REMOVE) {
p_stream = (void*) php_stream_fopen_from_fd(socket, "rw", NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, it's the best idea to use streams just a pure fd wrapper. In this case I would just use zend_long to contain it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the only purpose of the fd here is to be able to pass it to the polling mechanism and then call curl_multi_socket_action when ready so it should not be used for reading / writing by stream. If users want to use stream_select for polling then they should be able to do conversion using php://fd/$socketfd. That said I plan to look to an easier way how use pure fd in stream_select and the new polling API so this should get even easier in the future.

@krakjoe
Copy link
Member Author

krakjoe commented Sep 2, 2025

So, it looks most reasonable/elegant to wait for the new polling api so that we don't have to decorate the socket as a stream internally or externally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants